package com.briup.day13;

/**
 * @author ThinkBook
 */
public class Test04_Ball2 {
    public static void main(String[] args) {
        //1.实例化子类对象，用父类引用指向它
        Ball ball = new BasketBall2();

        //2.将父类引用 传递给Game对象start方法,实现功能
        Game2 game = new Game2();
        game.start(ball);

        System.out.println("-------------");

        ball = new Football2();
        game.start(ball);

        System.out.println("-------------");

        ball = new PingPang2();
        game.start(ball);
    }
}
//1.抽取父类
class Ball {
    public void play() {}
}

//2.定义各种具体球类(子类)
class BasketBall2 extends Ball {
    @Override
    public void play() {
        System.out.println("开启篮球游戏 ...");
    }
}

class Football2 extends Ball {
    @Override
    public void play() {
        System.out.println("开启足球游戏 ...");
    }
}

class PingPang2 extends Ball{
    @Override
    public void play(){
        System.out.println("开启乒乓球游戏");
    }
}

//3.定义Game，其中start(Ball ball)接收球类(父类)引用
class Game2 {
    public void start(Ball ball) {
        ball.play();
    }
}
